<?php
# Base class for RAWS entry classes.
#
# Copyright (C) 2008 rambla.be
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_once 'Zend/Gdata/Entry.php';
require_once dirname(__FILE__) . '/Extension/Content.php';

/**
 * Represents the Raws flavor of an Atom entry
 */
class Raws_Entry extends Zend_Gdata_Entry
{

    protected $_entryClassName = 'Raws_Entry';

    public function __construct($element = null)
    {
        foreach (Zend_Gdata::$namespaces as $nsPrefix => $nsUri) {
            $this->registerNamespace($nsPrefix, $nsUri);
        }
        parent::__construct($element);
    }

    public function get_self_url()
    {
      $url = null;
      foreach($this->link as $link) {
        if ($link->rel == "self") {
          $url = $link->href;
        }
      }
      return $url;
    }

    public function get_alternate_url()
    {
      $url = null;
      foreach($this->link as $link) {
        if ($link->rel == "alternate") {
          $url = $link->href;
        }
      }
      return $url;
    }

    public function get_edit_url()
    {
      $url = null;
      foreach($this->link as $link) {
        if ($link->rel == "edit") {
          $url = $link->href;
        }
      }
      return $url;
    }
    
    public function get_enclosure_url()
    {
      $url = null;
      foreach($this->link as $link) {
        if ($link->rel == "enclosure") {
          $url = $link->href;
        }
      }
      return $url;
    }

    /**
     * Return related jobs.
     *
     * @param Raws_Feed $feed Class derived from Raws_Feed
     * @return array Array that contains the URLs of related jobs.
     */
    public function get_related_job_urls()
    {
      $a_related = array();
      foreach($this->link as $link) {
        if ($link->rel == "job") {
          $a_related[] = $link->href;
        }
      }    
      return $a_related;
    }  

}
